<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <!-- 1. 具备宽高的容器 -->
  <div id="main" style="width: 600px; height: 400px;"></div>
  <div id="main2" style="width: 600px; height: 400px;"></div>
  <script src="./lib/echarts.min.js"></script>

  <script>

    initBarChart()
    initLineChart()

    function initBarChart() {
      // 初始化echarts实例
      const myChart = echarts.init(document.querySelector('#main'))

      // 准备配置项
      const option = {
        title: {
          text: 'ECharts 入门示例',
          textstyle: {
            color: 'red'
          }
        },
        tooltip: {},
        legend: {
          data: ['销量']
        },
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
          }
        ]
      }

      // 基于配置项，渲染图表
      myChart.setOption(option)
    }

    function initLineChart() {
      // 初始化echarts实例
      const myChart = echarts.init(document.querySelector('#main2'))

      // 准备配置项
      const option = {
        title: {
          text: '标题'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        // toolbox: {
        //   feature: {
        //     saveAsImage: {}
        //   }
        // },
        xAxis: {
          type: 'category',
          // boundaryGap: false,
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: 'Email',
            type: 'bar',
            // stack: 'Total',
            data: [120, 132, 101, 134, 90, 230, 210]
          },
          {
            name: 'Union Ads',
            type: 'bar',
            // stack: 'Total',
            data: [220, 182, 191, 234, 290, 330, 310]
          },
          {
            name: 'Video Ads',
            type: 'bar',
            // stack: 'Total',
            data: [150, 232, 201, 154, 190, 330, 410]
          },
          {
            name: 'Direct',
            type: 'bar',
            // stack: 'Total',
            data: [320, 332, 301, 334, 390, 330, 320]
          },
          {
            name: 'Search Engine',
            type: 'line',
            stack: 'Total',
            data: [820, 932, 901, 934, 1290, 1330, 1320]
          }
        ]
      };

      // 基于配置项，渲染图表
      myChart.setOption(option)
    }
  </script>
</body>

</html>